package com.yixun.qfbao.hander;

import com.yixun.qfbao.api.service.DataCenterService;
import com.yixun.qfbao.apidto.GetGroupReportPageReqDto;
import com.yixun.qfbao.apidto.GetGroupReportPageResDto;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.model.PartnerInfo;
import com.yixun.qfbao.utils.LoginUtils;
import com.yixun.qfbao.vo.GetGroupReportPageReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class GetGroupReportHander extends CommonAbstractHander {
    private static Logger logger= LoggerFactory.getLogger(GetGroupReportHander.class);
    @Autowired
    private DataCenterService dataCenterService;
    @Autowired
    private LoginUtils loginUtils;
    @Override
    public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
        BaseResponseDTO<GetGroupReportPageResDto> res = new BaseResponseDTO<>();
        GetGroupReportPageReqVo reqVo = (GetGroupReportPageReqVo)reqDto;
        GetGroupReportPageReqDto getGroupReportPageReqDto = reqVo.getParams();
        PartnerInfo pi = loginUtils.getUser(getGroupReportPageReqDto.getUserId());
        if (pi == null) {
            res.setResult(ResultEnum.FAIL.getNo());
            res.setErrorMsg("未获取到用户信息");
            return res;
        }
        getGroupReportPageReqDto.setDevCompanyId(pi.getHigherid());
        try {
            GetGroupReportPageResDto resDto = dataCenterService.getGroupReportPage(getGroupReportPageReqDto);
            res.setResult(resDto.getResult());
            res.setResData(resDto);
        } catch (Exception e) {
            logger.error("GetGroupReportHander error: {}", e);
            res.setResult(ResultEnum.FAIL.getNo());
            res.setErrorMsg("查询信息失败");
        }
        return res;
    }
}
